package com.xms.sdk.extensions;

import com.xms.core.enums.DateInterval;
import com.xms.schema.core.AttributeTypeIds;
import com.xms.schema.entity.Attribute;
import com.xms.sdk.core.query.ConditionExpression;
import com.xms.sdk.core.query.ConditionOperator;
import com.xms.utils.CollectionUtil;
import com.xms.utils.DateTimeUtil;
import com.xms.utils.StringUtil;

import java.util.Date;

/**
 * <p>
 * ConditionExpressionExtensions
 * </p>
 *
 * @author migo
 * @since 2021/9/3
 */
public class ConditionExpressionExt
{
    private static boolean ProcessEqual(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.INT:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) == Integer.parseInt(values[0].toString()));
                    }
                    break;

                //case AttributeTypeIds.DECIMAL:

                case AttributeTypeIds.FLOAT:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Float.parseFloat(cnd.Values.get(0).toString()) == Float.parseFloat(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.MONEY:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Float.parseFloat(cnd.Values.get(0).toString()) == Float.parseFloat(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.VARCHAR:
                    result = (cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.NVARCHAR:
                    result = (cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                /*case AttributeTypeIds.TEXT:
                    result = (cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;*/

                case AttributeTypeIds.PICKLIST:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) == Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.STATE:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) == Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.STATUS:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) == Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.BIT:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) == Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.LOOKUP:
                    result = (cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.OWNER:
                    result = (cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.PRIMARYKEY:
                    result = (cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.DATETIME:
                    result = ProcessDatetimeCondition(cnd, values);
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessNotEqual(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.INT:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) != Integer.parseInt(values[0].toString()));
                    }
                    break;

                //case AttributeTypeIds.DECIMAL:

                case AttributeTypeIds.FLOAT:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Float.parseFloat(cnd.Values.get(0).toString()) != Float.parseFloat(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.MONEY:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Float.parseFloat(cnd.Values.get(0).toString()) != Float.parseFloat(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.NVARCHAR:
                    result = (!cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.VARCHAR:
                    result = (!cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                /*case AttributeTypeIds.TEXT:
                    result = (!cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;*/

                case AttributeTypeIds.PICKLIST:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) != Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.STATE:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) != Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.STATUS:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) != Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.BIT:
                    if (StringUtil.notEmpty(values[0].toString()))
                    {
                        result = (Integer.parseInt(cnd.Values.get(0).toString()) != Integer.parseInt(values[0].toString()));
                    }
                    break;

                case AttributeTypeIds.LOOKUP:
                    result = (!cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.OWNER:
                    result = (!cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.PRIMARYKEY:
                    result = (!cnd.Values.get(0).toString().equalsIgnoreCase(values[0].toString()));
                    break;

                case AttributeTypeIds.DATETIME:
                    result = ProcessDatetimeCondition(cnd, values);
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessGreaterThan(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.isEmpty(values) || values[0] == null || values[0].toString().isEmpty())
        {
            result = false;
        }
        else
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.INT:
                    result = (Integer.parseInt(values[0].toString()) > Integer.parseInt(cnd.Values.get(0).toString()));
                    break;

                //case AttributeTypeIds.DECIMAL:

                case AttributeTypeIds.FLOAT:
                    result = (Float.parseFloat(values[0].toString()) > Float.parseFloat(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.MONEY:
                    result = (Float.parseFloat(values[0].toString()) > Float.parseFloat(cnd.Values.get(0).toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessGreaterEqual(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.isEmpty(values) || values[0] == null || values[0].toString().isEmpty())
        {
            result = false;
        }
        else
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.INT:
                    result = (Integer.parseInt(values[0].toString()) >= Integer.parseInt(cnd.Values.get(0).toString()));
                    break;

                //case AttributeTypeIds.DECIMAL:

                case AttributeTypeIds.FLOAT:
                    result = (Float.parseFloat(values[0].toString()) >= Float.parseFloat(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.MONEY:
                    result = (Float.parseFloat(values[0].toString()) >= Float.parseFloat(cnd.Values.get(0).toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessLessThan(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null && !values[0].toString().isEmpty())
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.INT:
                    result = (Integer.parseInt(values[0].toString()) < Integer.parseInt(cnd.Values.get(0).toString()));
                    break;

                //case AttributeTypeIds.DECIMAL:

                case AttributeTypeIds.FLOAT:
                    result = (Float.parseFloat(values[0].toString()) < Float.parseFloat(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.MONEY:
                    result = (Float.parseFloat(values[0].toString()) < Float.parseFloat(cnd.Values.get(0).toString()));
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessLessEqual(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null && !values[0].toString().isEmpty())
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.INT:
                    result = (Integer.parseInt(values[0].toString()) <= Integer.parseInt(cnd.Values.get(0).toString()));
                    break;

                //case AttributeTypeIds.DECIMAL:

                case AttributeTypeIds.FLOAT:
                    result = (Float.parseFloat(values[0].toString()) <= Float.parseFloat(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.MONEY:
                    result = (Float.parseFloat(values[0].toString()) <= Float.parseFloat(cnd.Values.get(0).toString()));
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessBeginsWith(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = StringUtil.startsWithIgnoreCase(cnd.Values.get(0).toString(), values[0].toString());
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessNotBeginWith(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = !StringUtil.startsWithIgnoreCase(cnd.Values.get(0).toString(), values[0].toString());
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessEndsWith(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = StringUtil.endsWithIgnoreCase(cnd.Values.get(0).toString(), values[0].toString());
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessNotEndWith(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = !StringUtil.endsWithIgnoreCase(cnd.Values.get(0).toString(), values[0].toString());
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessNotContain(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = !StringUtil.containsIgnoreCase(cnd.Values.get(0).toString(), values[0].toString());
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessContains(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = (cnd.Values.get(0).toString().contains(values[0].toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessIn(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = (cnd.Values.get(0).toString().contains(values[0].toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessNotIn(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = !(cnd.Values.get(0).toString().contains(values[0].toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessLike(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = (values[0].toString().contains(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.VARCHAR:
                    result = (values[0].toString().contains(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.TEXT:
                    result = (values[0].toString().contains(cnd.Values.get(0).toString()));
                    break;

                case AttributeTypeIds.NTEXT:
                    result = (values[0].toString().contains(cnd.Values.get(0).toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessNotLike(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        if (CollectionUtil.notEmpty(values) && values[0] != null)
        {
            switch (attr.getAttributetypename())
            {
                case AttributeTypeIds.NVARCHAR:
                    result = !(cnd.Values.get(0).toString().contains(values[0].toString()));
                    break;

                default:
                    break;
            }
        }
        return result;
    }

    private static boolean ProcessDatetimeCondition(ConditionExpression cnd, Object... values)
    {
        boolean result = false;
        if (values != null && values.length > 0 && values[0] != null && !values[0].toString().isEmpty())
        {
            switch (new Integer(String.valueOf(cnd.Operator)))
            {
                case ConditionOperator.Today:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)cnd.Values.get(0), 0), new Date()) == 0;
                    break;

                case ConditionOperator.Tomorrow:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)cnd.Values.get(0), 0), new Date()) == -1;
                    break;

                case ConditionOperator.Between:

                    break;

                case ConditionOperator.InFiscalPeriod:

                    break;

                case ConditionOperator.InFiscalPeriodAndYear:

                    break;

                case ConditionOperator.InFiscalYear:

                    break;

                case ConditionOperator.InOrAfterFiscalPeriodAndYear:

                    break;

                case ConditionOperator.InOrBeforeFiscalPeriodAndYear:

                    break;

                case ConditionOperator.Last7Days:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) <= 7;
                    break;

                case ConditionOperator.LastFiscalPeriod:

                    break;

                case ConditionOperator.LastFiscalYear:

                    break;

                case ConditionOperator.LastMonth:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) == 1;
                    break;

                case ConditionOperator.LastWeek:
                    result = DateTimeUtil.dateDiff(DateInterval.Weekday, DateTimeUtil.parse((String)values[0], 0), new Date()) == 1;
                    break;

                case ConditionOperator.LastXDays:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.LastXFiscalPeriods:

                    break;

                case ConditionOperator.LastXFiscalYears:

                    break;

                case ConditionOperator.LastXHours:
                    result = DateTimeUtil.dateDiff(DateInterval.Hour, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.LastXMonths:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.LastXWeeks:
                    result = DateTimeUtil.dateDiff(DateInterval.Weekday, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.LastXYears:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.LastYear:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) == 1;
                    break;

                case ConditionOperator.Next7Days:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) >= -7;
                    break;

                case ConditionOperator.NextFiscalPeriod:

                    break;

                case ConditionOperator.NextFiscalYear:

                    break;

                case ConditionOperator.NextMonth:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) == -1;
                    break;

                case ConditionOperator.NextWeek:
                    result = DateTimeUtil.dateDiff(DateInterval.Weekday, DateTimeUtil.parse((String)values[0], 0), new Date()) == -1;
                    break;

                case ConditionOperator.NextXDays:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) >= -Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.NextXFiscalPeriods:

                    break;

                case ConditionOperator.NextXFiscalYears:

                    break;

                case ConditionOperator.NextXHours:
                    result = DateTimeUtil.dateDiff(DateInterval.Hour, DateTimeUtil.parse((String)values[0], 0), new Date()) >= -Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.NextXMonths:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) < Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.NextXWeeks:
                    result = DateTimeUtil.dateDiff(DateInterval.Weekday, DateTimeUtil.parse((String)values[0], 0), new Date()) >= -Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.NextXYears:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) >= -Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.NextYear:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) == -1;
                    break;

                case ConditionOperator.NotBetween:

                    break;

                case ConditionOperator.OlderThanXYears:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.OlderThanXMonths:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.OlderThanXDays:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) >= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.AfterXYears:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) <= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.AfterXMonths:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) <= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.AfterXDays:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) <= Integer.parseInt(cnd.Values.get(0).toString());
                    break;

                case ConditionOperator.On:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) == 0;
                    break;

                case ConditionOperator.NotOn:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) != 0;
                    break;

                case ConditionOperator.OnOrAfter:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) <= 0;
                    break;

                case ConditionOperator.OnOrBefore:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) >= 0;
                    break;

                case ConditionOperator.ThisFiscalPeriod:

                    break;

                case ConditionOperator.ThisFiscalYear:

                    break;

                case ConditionOperator.ThisMonth:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) == 0;
                    break;

                case ConditionOperator.ThisWeek:
                    result = DateTimeUtil.dateDiff(DateInterval.Month, DateTimeUtil.parse((String)values[0], 0), new Date()) == 0;
                    break;

                case ConditionOperator.ThisYear:
                    result = DateTimeUtil.dateDiff(DateInterval.Year, DateTimeUtil.parse((String)values[0], 0), new Date()) == 0;
                    break;

                case ConditionOperator.Yesterday:
                    result = DateTimeUtil.dateDiff(DateInterval.Day, DateTimeUtil.parse((String)values[0], 0), new Date()) == 1;
                    break;
            }
        }
        return result;
    }

    public static boolean isTrue(ConditionExpression cnd, Attribute attr, Object... values)
    {
        boolean result = false;
        switch (new Integer(String.valueOf(cnd.Operator)))
        {
            case ConditionOperator.Equal:
                result = ProcessEqual(cnd, attr, values);
                break;

            case ConditionOperator.EqualUserId:
                result = ProcessEqual(cnd, attr, values);
                break;

            case ConditionOperator.NotEqual:
                result = ProcessNotEqual(cnd, attr, values);
                break;

            case ConditionOperator.NotEqualUserId:
                result = ProcessNotEqual(cnd, attr, values);
                break;

            case ConditionOperator.NotEqualBusinessId:
                result = ProcessNotEqual(cnd, attr, values);
                break;

            case ConditionOperator.BeginsWith:
                result = ProcessBeginsWith(cnd, attr, values);
                break;

            case ConditionOperator.DoesNotBeginWith:
                result = ProcessNotBeginWith(cnd, attr, values);
                break;

            case ConditionOperator.DoesNotContain:
                result = ProcessNotContain(cnd, attr, values);
                break;

            case ConditionOperator.DoesNotEndWith:
                result = ProcessNotEndWith(cnd, attr, values);
                break;

            case ConditionOperator.EndsWith:
                result = ProcessEndsWith(cnd, attr, values);
                break;

            case ConditionOperator.GreaterEqual:
                result = ProcessGreaterEqual(cnd, attr, values);
                break;

            case ConditionOperator.GreaterThan:
                result = ProcessGreaterThan(cnd, attr, values);
                break;

            case ConditionOperator.LessEqual:
                result = ProcessLessEqual(cnd, attr, values);
                break;

            case ConditionOperator.LessThan:
                result = ProcessLessThan(cnd, attr, values);
                break;

            case ConditionOperator.Last7Days:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastMonth:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastWeek:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastXDays:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastXHours:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastXMonths:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastXWeeks:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastXYears:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.LastYear:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.Next7Days:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextMonth:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextWeek:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextXDays:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextXHours:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextXMonths:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextXWeeks:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextXYears:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NextYear:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.Today:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NotBetween:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.Between:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.OlderThanXYears:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.OlderThanXMonths:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.OlderThanXDays:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.AfterXYears:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.AfterXMonths:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.AfterXDays:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.On:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NotOn:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.OnOrAfter:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.OnOrBefore:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.ThisMonth:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.ThisWeek:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.ThisYear:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.Tomorrow:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.Yesterday:
                result = ProcessDatetimeCondition(cnd, values);
                break;

            case ConditionOperator.NotIn:
                result = ProcessNotIn(cnd, attr, values);
                break;

            case ConditionOperator.In:
                result = ProcessIn(cnd, attr, values);
                break;

            case ConditionOperator.Like:
                result = ProcessLike(cnd, attr, values);
                break;

            case ConditionOperator.Contains:
                result = ProcessContains(cnd, attr, values);
                break;

            case ConditionOperator.NotLike:
                result = ProcessNotLike(cnd, attr, values);
                break;

            case ConditionOperator.NotNull:
                result = (CollectionUtil.notEmpty(values) && values[0] != null);
                break;

            case ConditionOperator.Null:
                result = (CollectionUtil.isEmpty(values) || values[0] == null);
                break;

            case ConditionOperator.EqualBusinessId:
                result = ProcessEqual(cnd, attr, values);
                break;

            case ConditionOperator.EqualOrganizationId:
                result = ProcessEqual(cnd, attr, values);
                break;

            case ConditionOperator.NotEqualOrganizationId:
                result = ProcessNotEqual(cnd, attr, values);
                break;

            default:
                break;
        }
        return result;
    }
}
